/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * guiUserView.java
 *
 * Created on 13/06/2011, 02:39:31
 */

package guiPlaylisted.view;

import dataPlaylisted.Playlist;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;

/**
 *
 * @author Administrador
 */
public class guiUserView extends javax.swing.JDialog {

    private UserView m_userView;

    private PlaylistView m_playlistView;

    /** Creates new form guiUserView */
    public guiUserView(java.awt.Frame parent, boolean modal) throws FileNotFoundException, IOException, ClassNotFoundException {
        super(parent, modal);
        initComponents();

        m_playlistView = PlaylistView.getInstance();

        m_userView = UserView.getInstance();
        this.initView(m_userView.getUser().getUserName());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel5 = new javax.swing.JLabel();
        jLbUserName = new javax.swing.JLabel();
        jComboPlaylists = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jLabel5.setName("jLabel5"); // NOI18N

        jLbUserName.setName("jLbUserName"); // NOI18N

        jComboPlaylists.setName("jComboPlaylists"); // NOI18N
        jComboPlaylists.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboPlaylistsActionPerformed(evt);
            }
        });

        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(guiPlaylisted.PlaylistedApp.class).getContext().getActionMap(guiUserView.class, this);
        jButton1.setAction(actionMap.get("onOk")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(guiPlaylisted.PlaylistedApp.class).getContext().getResourceMap(guiUserView.class);
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(138, 138, 138)
                        .addComponent(jLabel5))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(156, 156, 156)
                        .addComponent(jLbUserName))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(148, 148, 148)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(115, 115, 115)
                        .addComponent(jComboPlaylists, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(jButton1)))
                .addContainerGap(39, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addComponent(jLbUserName)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 97, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboPlaylists, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addGap(86, 86, 86))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboPlaylistsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboPlaylistsActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboPlaylistsActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    guiUserView dialog = new guiUserView(new javax.swing.JFrame(), true);
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                        public void windowClosing(java.awt.event.WindowEvent e) {
                            System.exit(0);
                        }
                    });
                    dialog.setVisible(true);
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(guiUserView.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(guiUserView.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(guiUserView.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    public void initView(String _name){
        jLbUserName.setText(_name);

        if(m_userView.getUser().getPlaylistList() != null){
            int size_style = m_userView.getUser().getPlaylistList().size();
            for (int i=0; i < size_style; i++){
                    jComboPlaylists.addItem("playlist: " + i);
            }
        }
    }

    @Action
    public void onOk() throws FileNotFoundException, IOException, ClassNotFoundException {
        Playlist _playlist;
        _playlist = new Playlist();

        String str = (String) jComboPlaylists.getSelectedItem();

        int size = m_userView.getUser().getPlaylistList().size();
        for (int i = 0; i< size; i++){
            if (str.equals("playlist: " + i))
                _playlist = m_userView.getUser().getPlaylistList().get(i);
        }
        m_playlistView.runPlaylistView(_playlist);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboPlaylists;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLbUserName;
    // End of variables declaration//GEN-END:variables

}
